package com.Web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.DateUtil;

import com.entity.Employee;



public class Chat extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			
		HttpSession session = request.getSession();

		Employee em = (Employee) session.getAttribute("em");
		String msg = request.getParameter("msg");
		
		Employee e = new Employee();
		e.setMsg(msg);
		e.setTime(DateUtil.getNow());
		e.setUsername(em.getUsername());
		
		ServletContext application = getServletContext();
		
		List<Employee> msgList= (List<Employee>) application.getAttribute("msgList");
		
		if(msgList == null) {
			msgList = new ArrayList<Employee>();
		}
		
		msgList.add(e);
		application.setAttribute("msgList", msgList);
			request.getRequestDispatcher("/WEB-INF/views/adminmain.jsp").forward(request, response);
	}


}
